<?php
include_once '../core/Conexion.php';
include_once '../core/GestionDb.php';


$consulta=GestionDb::consultaLibre("SELECT  * FROM USUARIO WHERE NICK='".$_REQUEST['nick']."' AND CLAVE='".$_REQUEST['password']."'");

if(pg_num_rows($consulta)>0)
{   
        session_start();
        $consulta2=GestionDb::consultaLibre("SELECT * FROM ALUMNO WHERE  NICK='".$_REQUEST['nick']."'");
        if(pg_num_rows($consulta2)) //verifica si el usuario es un alumno
        {
            $fila=pg_fetch_array($consulta);
            $_SESSION['usuario']=$fila[0];
            $fila1=pg_fetch_array($consulta2);
            $_SESSION['alumno']=$fila1[0];
            header("location: ../Alumnos/index.php ");
        }
        
        $consulta3=GestionDb::consultaLibre("SELECT * FROM EMPLEADO WHERE  NICK='".$_REQUEST['nick']."'");
        if(pg_num_rows($consulta3))//verifica si el usuario es un empleado
        {
            $fila=pg_fetch_array($consulta);
            $_SESSION['usuario']=$fila[0];
            $fila3=pg_fetch_array($consulta3);
            $_SESSION['profesor']=$fila3[0];
            header("location: ../Empleado/index.php");
        }
}
else
{
         header("location: ../login.php?error=1");
}

